#pragma once
#include "windows.h"
#include <winternl.h>

#pragma comment(lib,"ntdll.lib")

// IsDebuggerPresent
static bool xx_is_debug_1() {
	return IsDebuggerPresent();
}

// CheckRemoteDebuggerPresent
static bool xx_is_debug_2() {
	BOOL debuged = false;
	bool ret =  CheckRemoteDebuggerPresent(GetCurrentProcess(), &debuged);
	return ret && TRUE == debuged;
}

//ZwSetInformationThread ThreadHideFromDebugger
static bool xx_disable_debug() {
	typedef NTSTATUS(WINAPI* NTSETINFORMATIONTHREAD)(HANDLE, ULONG, PVOID, ULONG);
	static NTSETINFORMATIONTHREAD NtSetInformationThread = NULL;

	if (nullptr == NtSetInformationThread)
	{
		NtSetInformationThread = (NTSETINFORMATIONTHREAD)
			GetProcAddress(LoadLibraryA("ntdll.dll"), "ZwSetInformationThread");
		if (nullptr == NtSetInformationThread) {
			return false;
		}
		NtSetInformationThread(GetCurrentThread(), 17 /*ThreadHideFromDebugger*/, 0, 0);
	}
	return true;
}